Passed
Pull Request — develop (#256)
by Xaver
01:38
created

clientlayer.js ➔ ... ➔ L.GridLayer.extend.createTile   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 37
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 22
c 0
b 0
f 0
nc 3
dl 0
loc 37
rs 9.352
nop 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A clientlayer.js ➔ ... ➔ nodes.forEach 0 8 1
1
define(['leaflet', 'rbush', 'helper'],
2
  function (L, rbush, helper) {
3
    'use strict';
4
5
    return L.GridLayer.extend({
6
      mapRTree: function mapRTree(d) {
7
        return {
8
          minX: d.location.latitude, minY: d.location.longitude,
9
          maxX: d.location.latitude, maxY: d.location.longitude,
10
          node: d
11
        };
12
      },
13
      setData: function (data) {
14
        var rtreeOnlineAll = rbush(9);
15
16
        this.data = rtreeOnlineAll.load(data.nodes.online.filter(helper.hasLocation).map(this.mapRTree));
17
18
        // pre-calculate start angles
19
        this.data.all().forEach(function (n) {
20
          n.startAngle = (parseInt(n.node.node_id.substr(10, 2), 16) / 255) * 2 * Math.PI;
21
        });
22
        this.redraw();
23
      },
24
      createTile: function (tilePoint) {
25
        var tile = L.DomUtil.create('canvas', 'leaflet-tile');
26
27
        var tileSize = this.options.tileSize;
28
        tile.width = tileSize;
29
        tile.height = tileSize;
30
31
        if (!this.data) {
32
          return tile;
33
        }
34
35
        var ctx = tile.getContext('2d');
36
        var s = tilePoint.multiplyBy(tileSize);
37
        var map = this._map;
38
39
        var margin = 50;
40
        var bbox = helper.getTileBBox(s, map, tileSize, margin);
41
42
        var nodes = this.data.search(bbox);
43
44
        if (nodes.length === 0) {
45
          return tile;
46
        }
47
48
        var startDistance = 10;
49
50
        nodes.forEach(function (d) {
51
          var p = map.project([d.node.location.latitude, d.node.location.longitude]);
52
53
          p.x -= s.x;
54
          p.y -= s.y;
55
56
          helper.positionClients(ctx, p, d.startAngle, d.node, startDistance);
57
        });
58
59
        return tile;
60
      }
61
    });
62
  });
63